import axios from 'axios'
import api from "./server-api";

var _url = api.ip
// var _url = 'http://47.107.159.133:80'

const categoryList = (callback) => {
  const url = _url + '/category/list'
  axios.get(url).then(num => {
    callback && callback(num.data)
  })
}

const categoryDelApi = (categoryId, callback) => {
  const url = _url + '/category/?categoryId=' + categoryId
  axios.delete(url).then(num => {
    console.log(num);
    callback && callback(num)
  })
}

const dialogFormVisiblePutApi = (listPut, callback) => {
  var _listPut = new URLSearchParams();
  _listPut.append("categoryId",listPut.categoryId);
  _listPut.append("categoryName",listPut.categoryName);
  /*只根据id修改类型*/
  // _listPut.append("types",listPut.types);
  // _listPut.append("goods",listPut.goods);
   const url = _url + '/category/?' + _listPut;
  axios.put(url).then(num => {
    callback && callback(num.data);
  })
}

const dialogFormVisiblePostApi = (categoryName, callback) => {
  const url = _url + '/category/?categoryName=' + categoryName;
  axios.post(url).then(num => {
    callback && callback(num.data);
  })
}

const searchApi = (input, callback) => {
  const url = _url + '/category/?name=' + input;
  axios.get(url).then(num => {
    callback && callback(num.data);
  })
}

export {
  categoryList, // 自动刷新
  categoryDelApi, // 根据id删除类型
  dialogFormVisiblePutApi, // 根据id修改l类型
  dialogFormVisiblePostApi, //根据id添加类型
  searchApi,//模糊搜索
}
